﻿<UserControl x:Class="JsdEditor.ShapeView3D"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:tools="clr-namespace:_3DTools;assembly=3DTools"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             MouseWheel="UserControl_MouseWheel">
    <UserControl.Resources>
        <MaterialGroup x:Key="TileMaterial">
            <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                    <SolidColorBrush Color="#DD00FF00" />
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
            <SpecularMaterial SpecularPower="24">
                <SpecularMaterial.Brush>
                    <SolidColorBrush Color="#FF00FF00" />
                </SpecularMaterial.Brush>
            </SpecularMaterial>
        </MaterialGroup>
        <MaterialGroup x:Key="AltTileMaterial">
            <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                    <SolidColorBrush Color="#DD88FF88" />
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
            <SpecularMaterial SpecularPower="24">
                <SpecularMaterial.Brush>
                    <SolidColorBrush Color="#FF88FF88" />
                </SpecularMaterial.Brush>
            </SpecularMaterial>
        </MaterialGroup>
        <DiffuseMaterial x:Key="BackTileMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#DD00FF00" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <MaterialGroup x:Key="SelectedTileMaterial">
            <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                    <SolidColorBrush Color="#DD0000FF" />
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
            <SpecularMaterial SpecularPower="24">
                <SpecularMaterial.Brush>
                    <SolidColorBrush Color="#FF0000FF" />
                </SpecularMaterial.Brush>
            </SpecularMaterial>
        </MaterialGroup>
        <MaterialGroup x:Key="AltSelectedTileMaterial">
            <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                    <SolidColorBrush Color="#DD8888FF" />
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
            <SpecularMaterial SpecularPower="24">
                <SpecularMaterial.Brush>
                    <SolidColorBrush Color="#FF8888FF" />
                </SpecularMaterial.Brush>
            </SpecularMaterial>
        </MaterialGroup>
        <DiffuseMaterial x:Key="SelectedBackTileMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#DD000044" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <DiffuseMaterial x:Key="LandMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#EE660000" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <DiffuseMaterial x:Key="LandBackMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#88FF8888" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
    </UserControl.Resources>
    <Border Grid.Column="1" Grid.Row="1" BorderBrush="Gray" BorderThickness="1" Margin="5" Background="White">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border Grid.Column="1" Grid.Row="1" BorderBrush="Gray" BorderThickness="1" Margin="5" Background="White">
                <tools:TrackballDecorator>
                    <Viewport3D>
                        <Viewport3D.Camera>
                            <PerspectiveCamera Position="{Binding CameraPosition}" 
                                           LookDirection="{Binding LookDirection}" />
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Children>
                                <tools:ScreenSpaceLines3D Thickness="1" Color="Gray" Points="-50, 0, 0, 50, 0, 0" />
                                <tools:ScreenSpaceLines3D Thickness="1" Color="Gray" Points="0, -50, 0, 0, 50, 0" />
                                <tools:ScreenSpaceLines3D Thickness="1" Color="Gray" Points="0, 0, -50, 0, 0, 50" />
                            </ModelVisual3D.Children>
                            <ModelVisual3D.Content>
                                <Model3DGroup x:Name="mgRoot">
                                    <DirectionalLight Color="White" Direction="-2, -4, -1" />
                                    <!--DirectionalLight Color="White" Direction="1, 2, -1" /-->
                                    <Model3DGroup x:Name="mgShape">
                                        <Model3DGroup.Transform>
                                            <Transform3DGroup>
                                                <RotateTransform3D>
                                                    <RotateTransform3D.Rotation>
                                                        <AxisAngleRotation3D x:Name="anrX" Axis="1 0 0" />
                                                    </RotateTransform3D.Rotation>
                                                </RotateTransform3D>
                                                <RotateTransform3D>
                                                    <RotateTransform3D.Rotation>
                                                        <AxisAngleRotation3D x:Name="anrY" Axis="0 1 0" />
                                                    </RotateTransform3D.Rotation>
                                                </RotateTransform3D>
                                                <RotateTransform3D>
                                                    <RotateTransform3D.Rotation>
                                                        <AxisAngleRotation3D x:Name="anrZ" Axis="0 0 1" />
                                                    </RotateTransform3D.Rotation>
                                                </RotateTransform3D>
                                            </Transform3DGroup>
                                        </Model3DGroup.Transform>
                                    </Model3DGroup>
                                </Model3DGroup>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
                </tools:TrackballDecorator>
            </Border>
            <StackPanel Grid.Row="2" Grid.Column="1">
                <StackPanel Orientation="Horizontal">
                    <CheckBox Margin="0,5,0,0" Content="Show selected tile only" IsChecked="{Binding ShowSelectedTileOnly, Mode=TwoWay}" />
                    <CheckBox Margin="5,5,5,0" Content="Transparency"
                          Checked="TransparencyCheckBox_Checked"
                          Unchecked="TransparencyCheckBox_Checked" />
                    <Label Content="Filled Position Count:" Background="LightGray" />
                    <Label Content="{Binding FilledPositionCount}" Background="LightGray" />
                </StackPanel>
                <Label Content="Rotate" />
                <DockPanel>
                    <Label DockPanel.Dock="Left" Content="X: " />
                    <Slider Minimum="0" Maximum="360" Value="{Binding ElementName=anrX, Path=Angle}" />
                </DockPanel>
                <DockPanel>
                    <Label DockPanel.Dock="Left" Content="Y: " />
                    <Slider Minimum="0" Maximum="360" Value="{Binding ElementName=anrY, Path=Angle}" />
                </DockPanel>
                <DockPanel>
                    <Label DockPanel.Dock="Left" Content="Z: " />
                    <Slider Minimum="0" Maximum="360" Value="{Binding ElementName=anrZ, Path=Angle}" />
                </DockPanel>
            </StackPanel>
            <Slider Grid.Row="1" 
                Value="{Binding CameraPositionY, Mode=TwoWay}" 
                Orientation="Vertical" 
                Minimum="0" Maximum="100" />
            <Slider Grid.Column="1"  
                Minimum="0" Maximum="100" 
                Value="{Binding CameraPositionX, Mode=TwoWay}" />
            <Slider Grid.Column="2" Grid.Row="1"
                Orientation="Vertical"
                Value="{Binding CameraPositionZ, Mode=TwoWay}"
                Minimum="0" Maximum="100" />
        </Grid>
    </Border>
</UserControl>
